package light.head.dao.site;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import light.head.constant.Parm;
import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.PageBean;
import light.head.framework.utils.DateUtils;
import light.head.model.RecruitInfo;

/**
 * 企业发布招聘信息
 */
@Service
public class RecruitInfoDAO extends BaseDAO<RecruitInfo, Serializable> {
	public RESULT findByMap(Map<String, String> map, PageBean pageBean) {
		StringBuffer hql = new StringBuffer("FROM RecruitInfo ri WHERE 1 = 1");
		List<Object> list = null;
		if (map != null) {
			list = new ArrayList<Object>();
			String oc=map.get(Parm.OC);
			String post=map.get(Parm.POST);
			String name=map.get(Parm.NAME);
			String time1=map.get(Parm.TIME1);
			String time2=map.get(Parm.TIME2);
			String deleted = map.get(Parm.DELETED);
			if(oc!=""&&isNotNull(oc)){
				hql.append(" AND ri.oc = ? ");
				list.add(Integer.parseInt(oc));
			}
			if(post!=""&&isNotNull(post)){
				hql.append(" AND ri.post LIKE ? ");
				list.add("%" + post + "%");
			}
			if(name!=""&&isNotNull(name)){
				hql.append(" AND ri.name LIKE ? ");
				list.add("%" + name + "%");
			}
			if(time1!=""&&isNotNull(time1)){
				hql.append(" AND ri.ct >= ? ");
				list.add(DateUtils.getDateStr(time1, "yyyy-MM-dd"));
			}
			if(time2!=""&&isNotNull(time2)){
				hql.append(" AND ri.ct <= ? ");
				list.add(DateUtils.getDateStr(time2, "yyyy-MM-dd"));
			}
			if(deleted!=""&&isNotNull(deleted)){
				hql.append(" AND ri.deleted = ?");
				list.add(Boolean.parseBoolean(deleted));
			}
		}
		hql.append(" ORDER BY ri.ct DESC");
		return findToPageBean(hql.toString(), pageBean, list);
	}
}
